package com.example.cake.controller;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.cake.common.Result;
import com.example.cake.entity.DTO.SysFlavorDTO;
import com.example.cake.entity.SysAdmin;
import com.example.cake.entity.SysCustomer;
import com.example.cake.entity.SysFlavor;
import com.example.cake.service.SysAdminService;
import com.example.cake.service.SysFlavorService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/admin")
public class SysAdminController {
    @Autowired
    private SysAdminService sysAdminService;

    @PostMapping("/login")
    public Result loginByNameAndPassword(@RequestBody SysAdmin sysAdmin) {
        LambdaQueryWrapper<SysAdmin> lqw = new LambdaQueryWrapper<>();
        lqw.eq(SysAdmin::getUsername,sysAdmin.getUsername());
        lqw.eq(SysAdmin::getPassword,sysAdmin.getPassword());
        SysAdmin one = sysAdminService.getOne(lqw);
        if(one != null){
            return Result.success("200","登录成功",one);
        }else {
            return Result.error("账号或密码错误","-1");
        }
    }

    @PostMapping("/update")
    public Result update(@RequestBody SysAdmin sysAdmin) {
        return Result.success(sysAdminService.updateById(sysAdmin));
    }
}
